package chapter03

/**
 * @program lu-scala01
 * @description:
 * @author: zhanglu
 * @create: 2022-03-27 19:23:00
 */
object C17_Extends {

  def main(args: Array[String]): Unit = {

    val student: Student17 = new Student17("lu",18)
    student.study
    student.sayHi
    val person: Person17 = new Student17("lu", 24)
    person.sayHi

    //1.类型的检测
    println("student is Student17: " + student.isInstanceOf[Student17])
    println("student is Person17: " + student.isInstanceOf[Person17])
    println("person is Student17: " + person.isInstanceOf[Student17])
    println("person is Person17: " + person.isInstanceOf[Person17])

    val person2: Person17 = new Person17("lu", 25)
    println("person2 is Student17: " + person2.isInstanceOf[Student17])

    println("--------------")

    //2.类型的转换
    if(person.isInstanceOf[Student17]){
      val newStudent = person.asInstanceOf[Student17]
      newStudent.study
    }

    println(classOf[Student17])

  }

}

class Person17(val name: String, val age: Int){
  def sayHi: Unit ={
    println(s"hi from person $name")
  }
}

class Student17(name: String, age: Int) extends Person17(name, age){
  override def sayHi: Unit ={
    println(s"hi from student $name")
  }
  def study: Unit ={
    println("student study")
  }
}
